package cn.dinxian.leave.instener;;

import com.alibaba.fastjson.JSONObject;

import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.activiti.engine.delegate.Expression;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class LeaveEndStateListener implements ExecutionListener {

  private Expression state;
  @Autowired
  RuntimeService runtimeService;
  @Override
  public void notify(DelegateExecution delegateExecution) {
    String event = delegateExecution.getEventName();
    switch (event) {
      case "start":
        log.info("[MYLOG]:-----LeaveEndStateListener/notify==>start event:]");
        break;
      case "end":
        log.info("[MYLOG]:-----LeaveEndStateListener/notify==>end event:]");
        break;
      case "take":
        log.info("[MYLOG]:-----LeaveEndStateListener/notify==>take event:]");

        break;
    }
    //log.info("[MYLOG]:-----LeaveEndStateListener/notify==>delegateExecution:["+JSONObject.toJSONString(delegateExecution)+"]");
   //
   // WorkflowLeave workflowLeave = new WorkflowLeave();
   //  String msg = (String) delegateExecution.getVariables().get("variables");
   // workflowLeave.setId(delegateExecution.getProcessInstanceBusinessKey());
   //final String msg = SpringUtils.getBean(IProcessDefinitionService.class)
   //     .getvarious(delegateExecution.getId(), "FormProperty_3qipis2"); 
   ////通过业务id来查询
   // if (msg.equals("0")){
   //   workflowLeave.setState("1");
   // }
   // else {
   //   workflowLeave.setState("2");
   // }
   //
   // workflowLeave.setState(msg);
   // SpringUtils.getBean(IWorkflowLeaveService.class).updateWorkflowLeave(workflowLeave);
  }


  public String test(DelegateExecution delegateExecution) {
    return  runtimeService.getVariable(delegateExecution.getId(),"FormProperty_opt").toString();
  }

}
